$(function(){

	var detailId=queryString('detailId');
	requestDetail(detailId);
	alert(detailId);
	//责任人模态框弹出
	$("#Part").click(function(){
		$('#myPart').modal('show');
		requestStructucre();
	});
	//确定派遣按钮
	$("#requestTask").click(function(){
		$("#TaskModal").modal('show');
	})
	//派遣模态框，确认按钮
	$("#sureTask").click(function(){
		requestTask(detailId);
	})
})
//正则取链接传来的数据
function queryString(key)
{
    var regex_str = "^.+\\?.*?\\b"+ key +"=(.*?)(?:(?=&)|$|#)"
    var regex = new RegExp(regex_str,"i");
    var url = window.location.toString();
    if(regex.test(url)) return RegExp.$1;
    return undefined;
}
//根据id向后台请求数据详情
function requestDetail(id)
{
	//数据模拟
	var object={id:1,informationSource:"即时任务派遣安全排查",safetyPort:"日搜日结",
			informationSort:"即时任务派遣情报",informationClassification:"三级",
			inputPerson:"xxxx,xxx",informationProfile:"xsdadiao",
			Standard:"xdadabiao",Measure:"措施",informationContent:"xsdaaxdsadas",
			appendix:["/yuxi/vedioo/xuqin.mp4","/yuxi/vedioo/11.jpg"]
	};
	$("#valSource").html(object.informationSource);//渠道
	$("#valPort").html(object.safetyPort);//分口
	$("#valSort").html(object.informationSort);//分类
	$("#valClassification").html(object.informationClassification);//分级
	$("#valPerson").html(object.inputPerson);//参与人
	$("#valProfile").html(object.informationProfile);//简介
	$("#valStandard").html(object.Standard);//标准
	$("#valMeasure").html(object.Measure);//措施
	$("#valContent").html(object.informationContent);//内容
	YuXi.appendix.get(object.appendix);

}
//责任人数据请求
function requestStructucre()
{	var url="getStructucreLevel.do";//责任人地址
	var data={};
	var object={};
	YuXi.util.get(url,function(data){
		if(data.status){
			util.tree.start(data.object,$("#test-select"));
			$("#test-select").treeMultiselect({ enableSelectAll: true, sortable: true });
		}
	},function(){
		alert("error");
	});//请求数据
	
	/*  var s={"status":true,"msg":"获取监狱部门等级成功","object":[{"id":37,"name":"监狱","superId":0,"level":2},{"id":38,"name":"科室","superId":37,"level":3},{"id":41,"name":"一分监区","superId":38,"level":4},{"id":43,"name":"一科室","superId":38,"level":4},{"id":39,"name":"一监区","superId":37,"level":3},{"id":42,"name":"一分监区","superId":39,"level":4},{"id":40,"name":"二监区","superId":37,"level":3},{"id":44,"name":"科一","superId":40,"level":4}],"subTime":1469453325148,"subType":"获取操作"};
	*/  //调用js

}
//责任人选中后的确定按钮
function surePart()
{
	alert("surePart");
	 var item=$(".ui-sortable .item");
     $("#node").find(".label1").html("");
     var pearson="";
     for(var i=0;i<item.length;i++)
     {
       firt=item[i].firstChild;
       if(i==item.length-1)
       {
         pearson+=firt.nextSibling.nodeValue;
       }
       else
       {
         pearson+=firt.nextSibling.nodeValue+",";

       }
       html="<span class='parsbox'><span  class='glyphicon glyphicon-user' aria-hidden='true'></span>"+firt.nextSibling.nodeValue+"&nbsp;&nbsp;</span></span>"
       $(".label1").append(html);
     }
     $('#myPart').modal('hide');
	
}
//责任人搜索------------------
function search()
{
	var search=$("#searchInsert").val();//需要查询的数据
	if(search!="")
	{
		requestSearch(search);
	}
}
//责任人-向后台传送一个名字，根据字符串查询-------------------
function requestSearch(search)
{	var url="";//责任人地址
	search="name="+search;
	var object={};
	YuXi.util.get(url,search,function(data){
		util.tree.start(data.object,$("#test-select"));
	},function(){
	})
	object=data.object;
}
//确定派遣
function requestTask(id)
{
	alert("派遣任务ID"+id);
	//-------------------------获取责任人ID
	var information={};
	information.id=id;
	information.remark=$("#valRemark").val();
	var url="";//派遣地址
	YuXi.util.get(url,information,function(data){
		if(data.status)
		{
			$("#successmodel").modal('show');
			
		}
		else
		{
			$("#badmodal").modal('show');
		}
	},function(){
		$("#badmodal").modal('show');
	})
}